//
//  IntroScene.m
//  MessangerSkeleton
//
//  Created by User-16 on 4/1/14.
//  Copyright IOTrainingCamp 2014. All rights reserved.
//
// -----------------------------------------------------------------------

// Import the interfaces
#import "IntroScene.h"
#import "GameScene.h"
#import "LevelScene.h"

#import "GamePlay.h"

// -----------------------------------------------------------------------
#pragma mark - IntroScene
// -----------------------------------------------------------------------

@interface IntroScene ()

@property(nonatomic) GamePlay *gamePlay;

@end

@implementation IntroScene

// -----------------------------------------------------------------------
#pragma mark - Create & Destroy
// -----------------------------------------------------------------------

+ (IntroScene *)scene
{
	return [[self alloc] init];
}

// -----------------------------------------------------------------------

- (id)init
{
    // Apple recommend assigning self with supers return value
    self = [super init];
    if (!self) return(nil);
    
    self.gamePlay = [GamePlay sharedInstance];
    self.gamePlay.gameState = kGameStateNotPlaying;
    
    // Hello world
//    CCLabelTTF *label = [CCLabelTTF labelWithString:@"The Messanger" fontName:@"Chalkduster" fontSize:36.0f];
//    label.positionType = CCPositionTypeNormalized;
//    label.color = [CCColor redColor];
//    label.position = ccp(0.5f, 0.5f); // Middle of screen
//    [self addChild:label];
    
    CCSprite* background = [CCSprite spriteWithImageNamed:@"titleScreenFull.png"];
    [background setAnchorPoint: CGPointZero];
    [background setPosition:CGPointZero];
    [background setScale:0.95];
    [self addChild:background];
    
    
    //changed buttons - rev13
    // SinglePlayer scene button
    CCButton *helloWorldButton = [CCButton buttonWithTitle:@"[ Singleplayer ]" fontName:kSceneButtonFontNameVerdanaBold fontSize:18.0f];
    helloWorldButton.positionType = CCPositionTypeNormalized;
    helloWorldButton.position = ccp(0.3f, 0.5f);
    [helloWorldButton setColor:KSceneButtonFontColor];
    [helloWorldButton setTarget:self selector:@selector(pressedSignlePlayerButton:)];
    [self addChild:helloWorldButton];
    
    // Mute Button
    CCButton *muteButton = [CCButton buttonWithTitle:kSceneButtonTitleSounds fontName:kSceneButtonFontNameVerdanaBold fontSize:18.0f];
    muteButton.positionType = CCPositionTypeNormalized;
    muteButton.position = ccp(0.15f,0.95f);
//    [muteButton setTarget:self selector:@selector(muteSounds)];
    [muteButton setColor:KSceneButtonFontColor];
    [muteButton setTarget:[TransferSettings sharedInstance] selector:@selector(muteSounds)];
    [self addChild:muteButton];
    
 
   // MultiplayerPlayer scene button
    CCButton *multiplayerButton = [CCButton buttonWithTitle:@"[ Multiplayer ]" fontName:kSceneButtonFontNameVerdanaBold fontSize:18.0f];
    multiplayerButton.positionType = CCPositionTypeNormalized;
    multiplayerButton.position = ccp(0.7f, 0.5f);
    [multiplayerButton setTarget:self selector:@selector(pressedMultiplayerButton:)];
    [multiplayerButton setColor:KSceneButtonFontColor];
    [self addChild:multiplayerButton];
    
        
    //preloading audio effects
//    [self setupAudio];
    TransferSettings* transferedData = [TransferSettings sharedInstance];
    if (transferedData.soundsOn) {
        [[OALSimpleAudio sharedInstance] playBg:@"Raycast.m4a" loop:YES];
    }
    
    [[HighScoresDataManagerJson alloc] init];
//    [NSjso]
//    [NSJSONSerialization JSONObjectWithData:@[@5, @5] options:<#(NSJSONReadingOptions)#> error:<#(NSError *__autoreleasing *)#>];
    self.gamePlay.gamePosition = GamePlayNotPlaying;
    // done
	return self;
}

// -----------------------------------------------------------------------
#pragma mark - Button Callbacks
// -----------------------------------------------------------------------

- (void)pressedSignlePlayerButton:(id)sender
{
    self.gamePlay.gamePosition = GamePlaySingleplayer;
    self.gamePlay.gameState = kGameStateLaunchedSinglePlayer;
    self.gamePlay.characterType = kMessengerSelf;
    [[CCDirector sharedDirector] replaceScene:[LevelScene scene]
                               withTransition:[CCTransition transitionPushWithDirection:CCTransitionDirectionInvalid duration:1.0f]];
}

- (void)pressedMultiplayerButton:(id)sender
{
    self.gamePlay.gamePosition = GamePlayMultiplayer;
    self.gamePlay.gameState = kGameStateLaunchedMultiPlayer;
    [[CCDirector sharedDirector] replaceScene:[LevelScene scene]
                               withTransition:[CCTransition transitionPushWithDirection:CCTransitionDirectionInvalid duration:1.0f]];
}

@end
